#!/usr/bin/env node
var mvn_jar_func = function(act){
return `cat <<EOF > /usr/local/bin/mvn-${act}.sh
#!/usr/bin/env bash
p=$1
if [ -z "$p" ]
then
  echo bash mvn-${act}.sh 项目路径
  echo "mvn clean ${act} -Dmaven.test.skip=true -e -U  -am  -pl $*"
  exit 1
fi

mvn clean ${act} -Dmaven.test.skip=true -e -U  -am  -pl $*
EOF

chmod a+x /usr/local/bin/mvn-${act}.sh
`
}


mvn_jar_func("package")
mvn_jar_func("install")
mvn_jar_func("deploy")


var run_jar_func = ()=> {
    return `cat <<EOF > /usr/local/bin/run-jar.sh
#!/usr/bin/env bash
profile=$1
jar=$2
if [ -z "$profile"] then
  echo bash run-jar.sh profile 项目路径(默认为当前目录下的 .jar文件) 
  exit 1
fi

cd $(dirname $0)

if [ -z "$jar" ] then
    jar=\`ls -1 -F *.jar\`
fi

echo "当前路径:\`pwd\`,执行文件：$jar,环境:$profile"

mkdir -p lib
full_name=$jar-$profile
ps -ef | grep $full_name | grep -v grep | awk '{print $2}' | xargs -r kill -9  && \
  java -Xms750m -Xmx750m -XX:MaxMetaspaceSize=178m -XX:MetaspaceSize=178m -Xss512k \
  -Dfile.encoding=utf-8 -Dloader.path=lib -Dspring.cloud.bootstrap.enabled=true \
  -jar $jar \
  --spring.main.allow-bean-definition-overriding=true \
  --name=$full_name \
  --spring.profiles.active=$profile
`
}

run_jar_func()

